﻿function v(id) {
    return $("#ContentPlaceHolder1_" + id);
}
function Lantern(div,time,direction,lanterntype){
	var ul=div.find("ul:first");	
	var li=ul.find("li");
	var liSize=0;
	div.css({"position":"relative","visibility":"visible","overflow":"hidden"});
	ul.css({"position":"relative","left":"0","top":"0"});
	if(direction==0){
		ul.css({"width":"90000px"});
	}else{
		ul.css({"heigth":"90000px"});
	}
	for(var i=0;i<li.length;i++){
		if(direction==0){
			liSize+=$(li[i]).outerWidth();
		}else{
			liSize+=$(li[i]).outerHeight();	
		}
	}
    var count = 0;
	if(direction==0){
	    count = div.outerWidth() / liSize;
	}else{
	    count = div.outerHeight() / liSize;
}
    for (var i = 0; i < count; i++) {
	    ul.append(li.clone());
	}
	var movesize=0;
	var isstop=false;
	div.hover(
		function(){isstop=true;},
		function(){isstop=false;}
	);
	setInterval(function(){
		if(isstop)
			return;
		if(lanterntype==0){
			if(movesize==0-liSize){
				ul.css(direction==0?"left":"top",0);
				movesize=0;
				ul.find("li:first").appendTo(ul);
			}
			movesize--;
			ul.css(direction==0?"left":"top",movesize);
		}else{
			var firstli=ul.find("li:first");
			var firstliwidth=ul.find("li:first").outerWidth();
			ul.animate({"left":0-firstliwidth},1000,function(){
				$(this).css("left",0).append(firstli);
			});
		}
		
	},time);
}

var imgList=null,controlid="";
function BannerImg(){
    imgList=$(controlid).find("div");
    imgCount=imgList.length;
    if(imgList!=null &&imgCount>1){
        $(imgList[1]).fadeIn(5000,function(){
            $(imgList[0]).hide();
            $(imgList[0]).appendTo($(controlid));
        }); 
    }
}

function InitFlash(){
	var topnews=$("#TopNews");
	if(topnews.length>0){
		var titles=topnews.find(".title:first").find("li");
		var panel=topnews.find(".news_panel");
		titles.each(function(){
			$(this).hover(function(){
				titles.removeClass("curli");
				$(this).addClass("curli");
				var index=titles.index($(this));
				for(var i=0;i<panel.length;i++)
					if(i==index)
						$(panel[i]).show();
					else
						$(panel[i]).hide();
			},null);
		});
	}
	
	var subjectinfo=$("#SubjectInfo");
	if(subjectinfo.length>0){
	    var items = subjectinfo.find("li");
	    $(items[0]).addClass("curli");
		items.each(function(){
			$(this).hover(function(){
				items.removeClass("curli");
				$(this).addClass("curli");
			},null);	
		});
	}
	
	var itemequipment=$("#ItemEquipment");
	if(itemequipment.length>0){
		var itemtitles=itemequipment.find(".title:first").find("li");
		var itempanel=itemequipment.find(".item_imgs");
		itemtitles.each(function(){
			$(this).hover(function(){
				itemtitles.removeClass("curli");
				$(this).addClass("curli");
				var index=itemtitles.index($(this));
				for(var i=0;i<itempanel.length;i++)
					if(i==index)
						$(itempanel[i]).show();
					else
						$(itempanel[i]).hide();
			},null);
		});
	}
	
	var ItemLink=$("#ItemLink");
	if(ItemLink.length>0){
		var Linktitles=ItemLink.find(".title:first").find("li");
		var Linkpanel=ItemLink.find(".item_linkList");
		Linktitles.each(function(){
			$(this).hover(function(){
				Linktitles.removeClass("curli");
				$(this).addClass("curli");
				var index=Linktitles.index($(this));
				for(var i=0;i<Linkpanel.length;i++)
					if(i==index)
						$(Linkpanel[i]).show();
					else
						$(Linkpanel[i]).hide();
			},null);
		});
	}
	
	var AboutImgList=$("#AboutImgList");
	if(AboutImgList.length>0)
		Lantern($("#AboutImgList"),50,0,0);
	
	var EquipmentImgList=$("#EquipmentImgList");
	if (EquipmentImgList.length > 0 && EquipmentImgList.find("li").length>0)
		Lantern($("#EquipmentImgList"),2000,0,1);
		
	var EquipmentImgList1=$("#EquipmentImgList1");
	if (EquipmentImgList1.length > 0 && EquipmentImgList1.find("li").length > 0) {
	    var curdiv = $($("#ItemEquipment").find(".item_imgs")[1]);
	    curdiv.show();
	    Lantern($("#EquipmentImgList1"), 2000, 0, 1);
	    curdiv.hide();
	}

	if($("#banner").length>0){
		controlid="#banner";
    	setInterval(BannerImg,15000); 
	}
	
	if($("#AboutEquipmentImgList").length>0)
	   Lantern($("#AboutEquipmentImgList"),50,0,0);
	   
	var DoctorPanel=$("#DoctorPanel");
	if(DoctorPanel.length>0)
	    Lantern($("#DoctorPanel"), 50, 1, 0);

	var txtSearch = v("Search1_txtSearch");
	if (txtSearch.length > 0) {
	    txtSearch.focus(function () { $(this).val(""); });
	}

	if ($("#item_doctor_list").length > 0) {
	    Lantern($("#item_doctor_list"), 50, 0, 0);
    }
}

function ShowChat() {
    window.open("http://dgt.zoosnet.net/LR/chatwin.aspx?id=DGT86297732&lng=cn");
}

$(function(){
	InitFlash();
});

function changeImageChallenge() {
    var now = new Date();
    $("#imgValidateCode").attr("src", "../ValidateCode.aspx?t" + now.getTime());
}

function DoFaq() {
    var title = $("#txtTitle").val();
    var info = $("#txtInfo").val();
    if ($.trim(title)=="") {
        alert("请输入标题！");
        $("#txtTitle").focus();
        return false;
    }
    if ($.trim(info) == "") {
        alert("请输入内容！");
        $("#txtInfo").focus();
        return false;
    }
    WebRequest({ action: "faq", title: title, info: info, sortid: $("#ddlSubSort").val(), phone: $("#txtPhone").val(), email: $("#txtEmail").val(), code: $("#txtCode").val() },
    function (data) {
        if (data.result == 0) {
            if (data.msg != null) {
                switch (data.msg) {
                    case "notitle":
                        alert("请输入问题标题！");
                        break;
                    case "noinfo":
                        alert("请输入问题描述！");
                        break;
                    case "nocode":
                        alert("请输入验证码！");
                        break;
                    case "notcode":
                        alert("验证码不正确！");
                        break;
                }
            } else {
                alert("问题提交失败，请重试！");
            }
        } else if (data.result == 1) {
            alert("问题提交成功，请等待专家的答复！");
            $("#txtTitle").val("");
            $("#txtPhone").val("");
            $("#txtEmail").val("");
            $("#txtCode").val("");
            $("#txtInfo").val("");
        }

    });
}
//请求处理
function WebRequest(parms, callFun) {
    $.ajax({ type: "post",
        url: "/RequestProcessing.aspx",
        data: parms,
        dataType: "json",
        success: function (data) {
            if (Error(data)) { if (typeof callFun == 'function') callFun(data); }
        }
    });
}
//请求失败处理
function Error(data) {
    if (data != null) {
        if (data.result == -400) {
            alert("提交失败！");
            return false;
        }
    }
    return true;
}
function BindSort() {
    if ($("#ddlSort option").length == 0) {
        for (var i = 0; i < sortjson.length; i++) {
            $("#ddlSort").append("<option value=\"" + sortjson[i].sortid + "\">" + sortjson[i].name + "</option>");
        }
    }
    $("#ddlSubSort").empty();
    for (var i = 0; i < sortjson.length; i++) {
        if (sortjson[i].sortid == $("#ddlSort").val()) {
            for (var j = 0; j < sortjson[i].subsort.length; j++) {
                $("#ddlSubSort").append("<option value=\"" + sortjson[i].subsort[j].sortid + "\">" + sortjson[i].subsort[j].name + "</option>");
            }
        }
    }
}
